import { FormRule, PrimaryTableCol, Space, TableRowData } from 'tdesign-vue-next';

import { ActionBarItem } from '@/components/common-action-bar/index.vue';
import { t } from '@/locales';
import { tableActionBtn } from '@/utils/action';

export interface FormItem {
  id?: number;
  word: string;
  replaceWord?: string;
  classify: string;
  words?: string;
}

export const ACTION_BAR_DATA: ActionBarItem[] = [
  { text: 'common.add', theme: 'primary', auth: ['site:sencetive:create'], key: 'addShow' },
  {
    text: 'common.delete',
    theme: 'danger',
    auth: ['site:sencetive:batDel'],
    key: 'listBatDel',
    disabled: true,
    message: t('common.deleteSelectConfirm'),
  },
];

export const COLUMNS: PrimaryTableCol<TableRowData>[] = [
  { colKey: 'row-select', type: 'multiple', width: 46 },
  { colKey: 'id', title: 'ID', width: 100 },
  { colKey: 'word', title: () => t('pages.sensitive.word') },
  { colKey: 'replaceWord', title: () => t('pages.sensitive.replace') },
  { colKey: 'classify', title: () => t('pages.sensitive.classify') },
  { colKey: 'updatedAt', title: () => t('common.createAt') },
  {
    colKey: 'action',
    title: () => t('common.operation'),
    width: 150,
    cell(h, { row }) {
      const actionEdit = tableActionBtn({ h, type: 'edit', row, auths: ['site:sencetive:detail'] });
      const actionDelete = tableActionBtn({ h, type: 'delete', row, auths: ['site:sencetive:delete'] });
      return h(Space, () => {
        return [actionEdit, actionDelete];
      });
    },
  },
];

export const FORM_DATA: FormItem = {
  id: 0,
  word: '',
  replaceWord: '',
  classify: '',
  words: '',
};

export const FORM_RULES: Record<string, FormRule[]> = {
  word: [{ required: true, trigger: 'change' }],
  words: [{ required: true, trigger: 'change' }],
  classify: [{ required: true, trigger: 'change' }],
};
